package com.interfaces;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.common.web.Json;
import com.common.web.ReturnCodes;
import com.common.web.SelectJson;
import com.core.guarantee.dto.GuaranteeSearchCondition;
import com.core.guarantee.pojo.Guarantee;
import com.core.sysDict.bo.SysDictBo;
import com.core.sysDict.dto.SysDictSearchCondition;
import com.core.sysDict.pojo.SysDict;
import com.util.DataBaseUtil;
import com.util.GsonUtil;
import com.util.JSONUtil;
import com.util.exception.ComRuntimeException;
import com.util.exception.ComSystemException;
import com.util.framework.BaseController;


@Controller
public class SysDictController extends BaseController {
    protected Logger log = Logger.getLogger(this.getClass());

    @Resource
    private SysDictBo sysDictBo;
    
    public static final String URL_ENTITY = "/sysDict";
    public static final String URL_SEARCH = URL_ENTITY + "/search";
    public static final String URL_DB_SEARCH= URL_ENTITY+"/search1";
    public static final String URL_ADD = URL_ENTITY + "/add";
    public static final String URL_UPDATE = URL_ENTITY + "/update";
    public static final String URL_DEL = URL_ENTITY + "/del";
	public static final String URL_GOTO_MAIN_PAGE = URL_ENTITY + "/goto_main_page";
    public static final String URL_GOTO_ADD_PAGE = URL_ENTITY + "/goto_add_page";
    public static final String URL_GOTO_UPDATE_PAGE = URL_ENTITY + "/goto_update_page";
    @SuppressWarnings("unused")
	@ResponseBody
    @RequestMapping(value = URL_SEARCH, method = RequestMethod.POST,produces={"application/json;charset=utf-8"})
    public String searchSysDict(SysDictSearchCondition usc) {
        Json json = new Json();
        String msg="";
        try {
        	List<SelectJson> sysDictList = sysDictBo.search1Dto(usc);
            Integer totalRecordCount = sysDictBo.searchCnt(usc);
            msg=JSONUtil.toJSONstringNew(sysDictList);
            msg="{\"total_count\": "+totalRecordCount+",\"items\":"+ msg+"}";
        } catch (ComRuntimeException e) {
            json = new Json(e.getErrorCode(), e.getMessage());
        } catch (ComSystemException e) {
            log.error("error", e);
            json = new Json(e.getErrorCode(), "系统忙... " + e.getMessage());
        } catch (Throwable e) {
            log.error("error", e);
            json = new Json(ReturnCodes.SYSTEM_EXCEPTION, "系统忙... " + e.getMessage());
        }
        return msg.toString();
    }
    
}
